//
//  UITableView+Swizzled.m
//  Cargo
//
//  Created by chenliqun on 16/6/3.
//  Copyright © 2016年 chenliqun. All rights reserved.
//

#import "UITableView+Swizzled.h"
#import "HookUtility.h"
@implementation UITableView (Swizzled)

+ (void)load
{
    [super load];
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
//        SEL originalSelectorD = @selector(tableView:didSelectRowAtIndexPath:);
//        SEL swizzledSelectorD = @selector(swiz_tableView:didSelectRowAtIndexPath:);
//        
//        char* protocolName = "UITableViewDelegate";
//        //protocol_addMethodDescription
//        Protocol* p = objc_getProtocol(protocolName);
//        protocol_getMethodDescription(p, originalSelectorD, YES, YES);
//      
//        Class tbViewDelegate = objc_getClass(protocolName);
        
        //[HookUtility swizzlingInClass:p originalSelector:originalSelectorD swizzledSelector:swizzledSelectorD];
        //Protocol* p = objc_getProtocol(protocolName);
 
//        SEL originalSelector = @selector(selectRowAtIndexPath:animated:scrollPosition:);
//        SEL swizzledSelector = @selector(swiz_selectRowAtIndexPath:animated:scrollPosition:);
//        [HookUtility swizzlingInClass:[self class] originalSelector:originalSelector swizzledSelector:swizzledSelector];
    });
    
}


- (void)swiz_tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString* className = [NSString stringWithUTF8String:object_getClassName(self)];
    //NSLog(@"Hook %@ %s %@ OK\n\n", className, __PRETTY_FUNCTION__, self);
    
    [self swiz_tableView:tableView didSelectRowAtIndexPath:indexPath];
    
}


//- (void)swiz_selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
//{
//    NSString* className = [NSString stringWithUTF8String:object_getClassName(self)];
//    NSLog(@"Hook %@ %s %@ OK\n\n", className, __PRETTY_FUNCTION__, self);
//
//    [self swiz_selectRowAtIndexPath:indexPath animated:animated scrollPosition:scrollPosition];
//    
//}
@end
